#include <iostream>
#include <string>

//抽象原型类
class Monkey {
public:
    Monkey() = default;
    virtual ~Monkey() {};
    virtual Monkey* clone() = 0;
    virtual void play() = 0;
};

class SunWuKong : public Monkey {
public:
    SunWuKong(std::string name) {
        m_name = name;
    }
    //对于原型模式，如果类中含有指针变量，那么拷贝构造函数必须要实现深拷贝
    SunWuKong(const SunWuKong& other) {
        m_name = other.m_name;
    }
    ~SunWuKong() {
        std::cout << "~SunWuKong()" << std::endl;
    }
    virtual void play() {
        std::cout << "SunWuKong play" << std::endl;
    }
    virtual Monkey* clone() {
        return new SunWuKong(*this);
    }

private:
    std::string m_name;
};

int main(int argc, char const* argv[])
{
    Monkey* monkey = new SunWuKong("孙悟空");
    Monkey* monkey2 = monkey->clone();
    monkey2->play();
    delete monkey;
    delete monkey2;
    return 0;
}